<?php

/***************************************************************\
* FILE:		sys/pages/logs.inc
* SECTION:	pages > core set
* FUNCTION:	display logs
* USES:	
* INCLUDES:		
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

/**
 * adds extra access checks, dependent on page state
 */
function page_inc_check_access() {
	check_access("ADMIN");
}

/**
 *
 */
function page_inc_execute_action($action) {
	global $PAGE;
	switch($action) {
		default:
			add_alert("unknown action: $action");
			break;
	}
}

/**
 * execute page logic
 */
function page_inc_execute() {
	global $PAGE;

	$inputs = array();
	$inputs[] = form_input_select("Specifiek zoeken naar", "search_target", array('%', 'gebruiker #', 'item #'), array('algemeen', 'gebruikersnummer', 'itemnummer'));
	$inputs[] = form_input_field("Zoeken naar", "search_term");
	$PAGE['content']['form'] = form_create("searchform", $inputs);
	
	if ($_POST['search_term']) {
		$where = "log LIKE " . db_sqlize("%{$_POST['search_target']}{$_POST['search_term']}%");
	}	

	$sql = db_query_select(array(array('*')), array('LOG'), $where, "log_date DESC");
	$sqlresult = db_do_query($sql);
	
	$rows = array();
	while ($l = db_fetch_array($sqlresult)) {
		$rows[] = array(substr($l['log_date'],6,2) . "/" . substr($l['log_date'],4,2). "/" . substr($l['log_date'],0,4) . " " . substr($l['log_date'],8,2) . ":" . substr($l['log_date'],10,2), $l['ipstring'], $l['log']);
	}
	$headers = array("Datum", "IP", "actie");
	$widths = array(130, 170, 400);
	
	$PAGE['content']['table'] = array('headers' => $headers, 'rows' => $rows, 'widths' => $widths, 'aligns' => array());
	
}


/**
 * dress up page content using skin stuff
 */
function page_inc_dress() {
	global $PAGE;
	print_form($PAGE['content']['form']);
	print_table($PAGE['content']['table']);
}

?>